//! WhirliGig.debug.js
//

(function() {

Type.registerNamespace('ThemeChain');

////////////////////////////////////////////////////////////////////////////////
// ThemeWhirliGig

ThemeWhirliGig = function ThemeWhirliGig() {
    /// <field name="addSlideTitle" type="String" static="true">
    /// </field>
    /// <field name="nextSlideTitle" type="String" static="true">
    /// </field>
    /// <field name="prevSlideTitle" type="String" static="true">
    /// </field>
    /// <field name="remSlideTitle" type="String" static="true">
    /// </field>
    /// <field name="deleteMsg" type="String" static="true">
    /// </field>
    /// <field name="pageAddBtnTitle" type="String" static="true">
    /// </field>
    /// <field name="pageCancelBtnTitle" type="String" static="true">
    /// </field>
    /// <field name="pageAddDoneTitle" type="String" static="true">
    /// </field>
    /// <field name="_initialized$1" type="Boolean" static="true">
    /// </field>
    ThemeWhirliGig.initializeBase(this);
}


Type.registerNamespace('WhirliGig.Classes');

////////////////////////////////////////////////////////////////////////////////
// IGigShowEdit

IGigShowEdit = function() { 
};
IGigShowEdit.prototype = {
    configure : null,
    saveAllAw : null,
    newGigEdit : null,
    pageMenu : null,
    makeDraggable : null,
    undoStart : null,
    autoSize : null
}
IGigShowEdit.registerInterface('IGigShowEdit');


////////////////////////////////////////////////////////////////////////////////
// Gig

Gig = function Gig() {
    /// <field name="id" type="String">
    /// </field>
    /// <field name="content" type="jQueryObject">
    /// </field>
    /// <field name="deefCss" type="Object" static="true">
    /// </field>
    /// <field name="_extractGigClassRx$3" type="RegExp" static="true">
    /// </field>
    Gig.initializeBase(this);
    this.element = $("<div class='Gig'/>");
    this.setId(Formulas.get_newId());
}
Gig.parseContent = function Gig$parseContent(txt) {
    /// <param name="txt" type="String">
    /// </param>
    /// <returns type="jQueryObject"></returns>
    Gig._extractGigClassRx$3.lastIndex = 0;
    var mx = Gig._extractGigClassRx$3.exec(txt);
    if (mx != null && mx.length > 1) {
        try {
            return eval('new ' + mx[1] + '().Content()');
        }
        catch (ex) {
            var s = ex.toString();
            return $('<div>' + s + '</div>');
        }
    }
    return $(txt);
}
Gig.prototype = {
    id: null,
    content: null,
    
    draggable: function Gig$draggable(opt, doneFn) {
        /// <param name="opt" type="Object">
        /// </param>
        /// <param name="doneFn" type="Function">
        /// </param>
    },
    
    appendTo: function Gig$appendTo(el) {
        /// <param name="el" type="jQueryObject">
        /// </param>
        /// <returns type="Gig"></returns>
        this.element.appendTo(el);
        return this;
    },
    
    addClass: function Gig$addClass(cls) {
        /// <param name="cls" type="String">
        /// </param>
        /// <returns type="Gig"></returns>
        if (!String.isNullOrEmpty(cls)) {
            this.element.addClass(cls);
        }
        return this;
    },
    
    addAttr: function Gig$addAttr(attr) {
        /// <param name="attr" type="Object">
        /// </param>
        /// <returns type="Gig"></returns>
        if (attr != null && Object.getKeyCount(attr) > 0) {
            this.element.attr(attr);
        }
        return this;
    },
    
    addCss: function Gig$addCss(css) {
        /// <param name="css" type="Object">
        /// </param>
        /// <returns type="Gig"></returns>
        if (css != null && Object.getKeyCount(css) > 0) {
            this.element.css(css);
        }
        return this;
    },
    
    addType: function Gig$addType(type) {
        /// <param name="type" type="String">
        /// </param>
        /// <returns type="Gig"></returns>
        if (!String.isNullOrEmpty(type)) {
            this.element.data('gigType', type);
        }
        return this;
    },
    
    addHasHeight: function Gig$addHasHeight(has) {
        /// <param name="has" type="Boolean">
        /// </param>
        /// <returns type="Gig"></returns>
        this.element.data('gigHasHeight', has);
        return this;
    },
    
    addTilt: function Gig$addTilt(deg) {
        /// <param name="deg" type="Number">
        /// </param>
        /// <returns type="Gig"></returns>
        this.element.data('gigTilt', deg);
        this.element[0].tilt = deg;
        this.element.rotate({ angle: deg });
        return this;
    },
    
    setId: function Gig$setId(id) {
        /// <param name="id" type="String">
        /// </param>
        /// <returns type="Gig"></returns>
        this.id = id || this.id;
        this.element.attr('id', this.id);
        return this;
    },
    
    pos: function Gig$pos(how) {
        /// <param name="how" type="Object">
        /// </param>
        /// <returns type="Gig"></returns>
        this.element.position(how);
        return this;
    },
    
    dim: function Gig$dim(width, height) {
        /// <param name="width" type="Number" integer="true">
        /// </param>
        /// <param name="height" type="Number" integer="true">
        /// </param>
        /// <returns type="Gig"></returns>
        this.element.width(width);
        if (arguments.length > 1) {
            this.element.height(height);
        }
        return this;
    },
    
    fromHtml: function Gig$fromHtml(html) {
        /// <param name="html" type="String">
        /// </param>
        /// <returns type="Gig"></returns>
        this.content = $(html).prependTo(this.element);
        return this;
    },
    
    fromElement: function Gig$fromElement(el) {
        /// <param name="el" type="jQueryObject">
        /// </param>
        /// <returns type="Gig"></returns>
        this.content = el;
        el.prependTo(this.element);
        this.element.data('Gig', this);
        return this;
    }
}


////////////////////////////////////////////////////////////////////////////////
// WhirliGig.Classes.SlideData

WhirliGig.Classes.SlideData = function WhirliGig_Classes_SlideData() {
    /// <field name="slide" type="Number" integer="true">
    /// </field>
    /// <field name="interval" type="Number" integer="true">
    /// </field>
    /// <field name="css" type="Object">
    /// </field>
    /// <field name="style" type="String">
    /// </field>
    /// <field name="hasBackground" type="Boolean">
    /// </field>
    /// <field name="gigs" type="Object">
    /// </field>
    /// <field name="build" type="String">
    /// </field>
    /// <field name="curate" type="String">
    /// </field>
    /// <field name="load" type="String">
    /// </field>
    /// <field name="loadCss" type="String">
    /// </field>
    /// <field name="embedGap" type="Number" integer="true">
    /// </field>
    this.css = {};
}
WhirliGig.Classes.SlideData.prototype = {
    slide: 0,
    interval: 5000,
    style: null,
    hasBackground: false,
    gigs: null,
    build: null,
    curate: null,
    load: null,
    loadCss: null,
    embedGap: 0
}


////////////////////////////////////////////////////////////////////////////////
// WhirliGig.Classes.GigData

WhirliGig.Classes.GigData = function WhirliGig_Classes_GigData(showSelectTo) {
    /// <param name="showSelectTo" type="String">
    /// </param>
    /// <field name="classNames" type="String">
    /// </field>
    /// <field name="css" type="Object">
    /// </field>
    /// <field name="attributes" type="Object">
    /// </field>
    /// <field name="dim" type="WhirliGig.Classes.Dimension">
    /// </field>
    /// <field name="hasHeight" type="Boolean">
    /// </field>
    /// <field name="html" type="String">
    /// </field>
    /// <field name="id" type="String">
    /// </field>
    /// <field name="iid" type="String">
    /// </field>
    /// <field name="off" type="WhirliGig.Classes.Pos">
    /// </field>
    /// <field name="pos" type="WhirliGig.Classes.Pos">
    /// </field>
    /// <field name="selecTo" type="String">
    /// </field>
    /// <field name="tilt" type="Number">
    /// </field>
    /// <field name="type" type="String">
    /// </field>
    /// <field name="listType" type="String">
    /// </field>
    /// <field name="floated" type="Boolean">
    /// </field>
    /// <field name="embedded" type="Boolean">
    /// </field>
    /// <field name="autosize" type="Boolean">
    /// </field>
    /// <field name="cornerRadius" type="Number" integer="true">
    /// </field>
    /// <field name="groupId" type="String">
    /// </field>
    this.css = {};
    this.dim = new WhirliGig.Classes.Dimension();
    this.id = Formulas.get_newId();
    this.off = new WhirliGig.Classes.Pos();
    this.pos = new WhirliGig.Classes.Pos();
    this.selecTo = showSelectTo;
}
WhirliGig.Classes.GigData.prototype = {
    classNames: '',
    attributes: null,
    hasHeight: false,
    html: null,
    iid: null,
    selecTo: null,
    tilt: 0,
    type: null,
    listType: null,
    floated: false,
    embedded: false,
    autosize: false,
    cornerRadius: 0,
    groupId: null
}


////////////////////////////////////////////////////////////////////////////////
// WhirliGig.Classes.Pos

WhirliGig.Classes.Pos = function WhirliGig_Classes_Pos() {
    /// <field name="left" type="Number" integer="true">
    /// </field>
    /// <field name="top" type="Number" integer="true">
    /// </field>
}
WhirliGig.Classes.Pos.prototype = {
    left: 0,
    top: 0
}


////////////////////////////////////////////////////////////////////////////////
// WhirliGig.Classes.Dimension

WhirliGig.Classes.Dimension = function WhirliGig_Classes_Dimension() {
    /// <field name="height" type="Number" integer="true">
    /// </field>
    /// <field name="width" type="Number" integer="true">
    /// </field>
}
WhirliGig.Classes.Dimension.prototype = {
    height: 0,
    width: 0
}


////////////////////////////////////////////////////////////////////////////////
// WhirliGig.Classes.GigShowConfig

WhirliGig.Classes.GigShowConfig = function WhirliGig_Classes_GigShowConfig() {
    /// <field name="inner" type="String">
    /// </field>
    /// <field name="rounding" type="Boolean">
    /// </field>
    /// <field name="css" type="Boolean">
    /// </field>
    /// <field name="doubleclick" type="Boolean">
    /// </field>
}
WhirliGig.Classes.GigShowConfig.prototype = {
    inner: null,
    rounding: false,
    css: false,
    doubleclick: false
}


////////////////////////////////////////////////////////////////////////////////
// GigShow

GigShow = function GigShow() {
    /// <field name="_slideFade$2" type="Number" integer="true" static="true">
    /// </field>
    /// <field name="curating" type="Boolean">
    /// </field>
    /// <field name="defaultInterval" type="Number" integer="true">
    /// </field>
    /// <field name="editing" type="Boolean">
    /// </field>
    /// <field name="editor" type="IGigShowEdit">
    /// </field>
    /// <field name="lastSaved" type="String">
    /// </field>
    /// <field name="pageCssTo" type="String">
    /// </field>
    /// <field name="pageSelectTo" type="String" static="true">
    /// </field>
    /// <field name="pageSelectToEl" type="jQueryObject" static="true">
    /// </field>
    /// <field name="partitionKey" type="String">
    /// </field>
    /// <field name="rowKey" type="String">
    /// </field>
    /// <field name="slide" type="Number" integer="true">
    /// </field>
    /// <field name="slideControls" type="jQueryObject">
    /// </field>
    /// <field name="slides" type="Array">
    /// </field>
    /// <field name="_hasSelect" type="Boolean">
    /// </field>
    /// <field name="_opts" type="Object">
    /// </field>
    /// <field name="_playTmr" type="Number" integer="true">
    /// </field>
    /// <field name="instance" type="GigShow" static="true">
    /// </field>
    /// <field name="cssMap" type="Object" static="true">
    /// </field>
    this.slides = [];
    GigShow.initializeBase(this);
}
GigShow.gigElById = function GigShow$gigElById(id) {
    /// <param name="id" type="String">
    /// </param>
    /// <returns type="jQueryObject"></returns>
    return $((id.substr(0, 1) === '#') ? id : '#' + id, GigShow.pageSelectToEl);
}
GigShow.gigElBySelect = function GigShow$gigElBySelect(sel) {
    /// <param name="sel" type="String">
    /// </param>
    /// <returns type="jQueryObject"></returns>
    return $(sel, GigShow.pageSelectToEl);
}
GigShow.blankSlide = function GigShow$blankSlide() {
    /// <returns type="WhirliGig.Classes.SlideData"></returns>
    var sd = new WhirliGig.Classes.SlideData();
    sd.gigs = {};
    sd.css = ThemeYoshi.defaultPageCss;
    return sd;
}
GigShow._fixGd$2 = function GigShow$_fixGd$2(gd) {
    /// <param name="gd" type="WhirliGig.Classes.GigData">
    /// </param>
    gd.css = gd.css || {};
    gd.floated = ss.isValue(gd.floated) && gd.floated;
    gd.embedded = ss.isValue(gd.embedded) && gd.embedded;
}
GigShow.mapCss = function GigShow$mapCss(gd, el, css) {
    /// <param name="gd" type="WhirliGig.Classes.GigData">
    /// </param>
    /// <param name="el" type="jQueryObject">
    /// </param>
    /// <param name="css" type="Object">
    /// </param>
    var opt = GigShow.cssMap[gd.type];
    if (opt == null) {
        el.css(css);
        return;
    }
    var sel = $(opt.inner, el);
    if (sel.length > 0) {
        var br = parseInt((gd.css['border-radius'] || 0).toString());
        var bw = Css.borderWidth(gd.css);
        br = Math.max(br - bw, 0);
        if (opt.rounding) {
            sel.css({ '-moz-border-radius': br, '-webkit-border-radius': br, 'border-radius': br });
        }
        if (opt.css) {
            var wd = Css.paddingHorz(gd.css) + (bw * 2);
            var ht = Css.paddingVert(gd.css) + (bw * 2);
            sel.css(css);
            sel.css({ width: gd.dim.width - wd, height: gd.dim.height - ht });
        }
        else {
            el.css(css);
        }
    }
    else {
        el.css(css);
    }
}
GigShow.getTilts = function GigShow$getTilts() {
    /// <returns type="Object"></returns>
    var tilts = {};
    var $dict1 = GigShow.instance.get_currentSlide().gigs;
    for (var $key2 in $dict1) {
        var gigs = { key: $key2, value: $dict1[$key2] };
        var gd = gigs.value;
        if (('tilt' in gd) && !!gd.tilt) {
            tilts[gd.id] = gd.tilt;
        }
    }
    return tilts;
}
GigShow.PublishPagePx = function GigShow$PublishPagePx(nxt) {
    /// <param name="nxt" type="Number" integer="true">
    /// </param>
    new Await().loadScript(Uri.scripts('Scripts/WhirliGigEdit.js')).addDx(function() {
        Publish.PublishPage(nxt);
    }).commit();
}
GigShow.PublishThisPagePx = function GigShow$PublishThisPagePx() {
    new Await().loadScript(Uri.scripts('Scripts/WhirliGigEdit.js')).addDx(function() {
        Publish.PublishThisPage();
    }).commit();
}
GigShow.prototype = {
    curating: false,
    defaultInterval: 5000,
    editing: false,
    editor: null,
    lastSaved: null,
    pageCssTo: null,
    partitionKey: null,
    rowKey: null,
    slide: 0,
    slideControls: null,
    _hasSelect: false,
    _opts: null,
    _playTmr: 0,
    
    get_currentSlide: function GigShow$get_currentSlide() {
        /// <value type="WhirliGig.Classes.SlideData"></value>
        return this.slides[this.slide];
    },
    
    gigById: function GigShow$gigById(id) {
        /// <param name="id" type="String">
        /// </param>
        /// <returns type="WhirliGig.Classes.GigData"></returns>
        return this.get_currentSlide().gigs[id];
    },
    
    get_bgImgName: function GigShow$get_bgImgName() {
        /// <value type="String"></value>
        return 'background.jpg';
    },
    
    initializeAw: function GigShow$initializeAw(awp, opt) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="opt" type="Object">
        /// </param>
        GigShow.instance = this;
        this._opts = opt;
        this.partitionKey = opt['PartitionKey'];
        this.rowKey = opt['RowKey'];
        GigShow.pageSelectTo = opt['PageSelectTo'];
        GigShow.pageSelectToEl = $(GigShow.pageSelectTo);
        this.pageCssTo = opt['PageCssTo'];
        this.slideControls = opt['SlideControls'];
        this._hasSelect = (opt['HasSelect'] || false);
        ThemeBase.activePage = ThemeYoshi.get_currentPage().Admin;
        new Await().loadCss(Uri.scripts('Css/WhirliGig.css')).commit(awp);
        if (this.editing) {
            this.editor = this;
        }
    },
    
    destroy: function GigShow$destroy() {
        window.clearInterval(this._playTmr);
    },
    
    redrawPageGear: function GigShow$redrawPageGear() {
        if (this.editor != null) {
            this.editor.pageMenu();
        }
    },
    
    loadAw: function GigShow$loadAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        ss.Debug.assert(this.rowKey != null, 'rowKey != null');
        ThemeYoshi.pageDone = false;
        new Await().waitDx(function() {
            return $(GigShow.pageSelectTo).length > 0;
        }).addAw(FileBlobBase.retrieveBlobStringAw, this.partitionKey, this.rowKey).handleDl(Exceptions.blobLoadError, ss.Delegate.create(this, function(aw) {
            this.slides = [];
            this.slides.add(GigShow.blankSlide());
            this.redrawPageGear();
            new Await().addAw(ss.Delegate.create(this, this.restoreSlideAw), 0).addDx(function() {
                Await.finishAw(aw);
            }).commit();
            ThemeYoshi.pageDone = true;
            var pr = aw.get_item('Data');
            if (!pr.result && !pr.inactive && pr.msg === 'invalid credentials') {
                Inform.debug('Asking for credentials');
                $(document).trigger('AskCredentials');
            }
        })).addDl(ss.Delegate.create(this, function(aw) {
            GigShow.pageSelectToEl = $(GigShow.pageSelectTo);
            GigShow.pageSelectToEl.addClass('Slides');
            var email = aw.get_item('Data').email;
            if (!String.isNullOrEmpty(email)) {
                ThemeYoshi.email = email;
                ThemeYoshi.userId = aw.get_item('Data').userid;
            }
            this.lastSaved = aw.get_item(PkgBase.resultRx);
            if (this.editor != null) {
                this.editor.undoStart(this.lastSaved, this.slide);
            }
            this.slides = JSON.parse(this.lastSaved);
            var $enum1 = ss.IEnumerator.getEnumerator(this.slides);
            while ($enum1.moveNext()) {
                var sd = $enum1.current;
                this.normalize(sd);
            }
            this.redrawPageGear();
            if (ThemeYoshi.get_currentPage().Admin) {
                this.editing = false;
                this.editor = null;
            }
            this.restoreSlideAw(aw, 0);
        })).addDx(ss.Delegate.create(this, function() {
            if (ThemeBase.publishing) {
                $(this.pageCssTo).show();
            }
            else {
                $(this.pageCssTo).fadeIn(300);
            }
        })).addFn(ss.Delegate.create(this, this.fixBodyBg)).addDx(function() {
            ThemeYoshi.pageDone = true;
        }).commit(awp);
    },
    
    restoreSlideAw: function GigShow$restoreSlideAw(awp, slide) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="slide" type="Number" integer="true">
        /// </param>
        this.slide = slide;
        GigShow.pageSelectToEl.empty();
        $('head style').remove();
        if (!String.isNullOrEmpty(this.get_currentSlide().style)) {
            $('<style/>').append(this.get_currentSlide().style).appendTo('head');
        }
        if (this.get_currentSlide().gigs != null) {
            var interval = this.get_currentSlide().interval;
            this.get_currentSlide().interval = (typeof(interval) === 'undefined' || interval < 1000) ? this.defaultInterval : interval;
            if (!String.isNullOrEmpty(this.pageCssTo)) {
                var css2 = $.extend({}, this.get_currentSlide().css);
                if (this.get_currentSlide().hasBackground) {
                    css2['background-image'] = ThemeYoshi.bgImgUrl;
                }
                $(this.pageCssTo).css(css2);
                this.setBackgroundColor(css2['background-color']);
            }
            if (this.editor != null && !ThemeYoshi.get_currentPage().Admin) {
                $('#PageContent').addClass('PageEdge');
            }
            var awx = new Await();
            awx.addAw(ss.Delegate.create(this, this.loadActionAw));
            var $dict1 = this.get_currentSlide().gigs;
            for (var $key2 in $dict1) {
                var p = { key: $key2, value: $dict1[$key2] };
                this._restoreClosure$2(awx, p.value);
            }
            awx.addFn(ss.Delegate.create(this, this.setMinPageHeight));
            awx.addFn(ss.Delegate.create(this, this.buildAction));
            awx.commit(awp);
        }
        else {
            this.setMinPageHeight();
        }
    },
    
    fixBodyBg: function GigShow$fixBodyBg() {
        $(document.body).height($(document).height());
    },
    
    setBackgroundColor: function GigShow$setBackgroundColor(c) {
        /// <param name="c" type="String">
        /// </param>
        $(this.pageCssTo).css('background-color', '');
        $('html').css({ 'background-color': '' });
        $(document.body).css({ 'background-color': '' });
        if (Css.isPartialColor(c)) {
            var hb = Css.getColor($('html').css('background-color'));
            if (hb.red !== 255 || hb.green !== 255 || hb.blue !== 255) {
                $('html').css({ 'background-color': '#FFF' });
            }
        }
        $(document.body).css({ 'background-color': c });
        this.fixBodyBg();
    },
    
    _restoreClosure$2: function GigShow$_restoreClosure$2(awp, gd) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="gd" type="WhirliGig.Classes.GigData">
        /// </param>
        awp.addDl(ss.Delegate.create(this, function(aw) {
            this.injectIntoPageAw(aw, gd, (this.editing && !this._playTmr) ? this.editor.newGigEdit(this) : new Gig());
        }));
    },
    
    injectIntoPageAw: function GigShow$injectIntoPageAw(awp, gd, gg) {
        /// <param name="awp" type="Await">
        /// </param>
        /// <param name="gd" type="WhirliGig.Classes.GigData">
        /// </param>
        /// <param name="gg" type="Gig">
        /// </param>
        /// <returns type="Gig"></returns>
        gg.setId(gd.id);
        GigShow._fixGd$2(gd);
        this.get_currentSlide().gigs[gd.id] = gd;
        var where = $(gd.selecTo);
        if (!!where.length) {
            var awx = new Await().addDx(ss.Delegate.create(this, function() {
                gg.fromElement(Gig.parseContent(gd.html)).addClass(gd.classNames).addAttr(gd.attributes).addType(gd.type).addHasHeight(gd.hasHeight);
                if (!String.isNullOrEmpty(gd.iid)) {
                    gg.element.find('.GigC').attr('id', gd.iid);
                }
                gg.appendTo(where);
                gg.element.css({ position: 'absolute', top: gd.pos.top, left: gd.pos.left, width: gd.dim.width });
                if (gd.hasHeight) {
                    gg.element.css({ height: gd.dim.height });
                }
                var css = gd.css;
                if (this.editor != null) {
                    css = this.editor.configure(gd, gg);
                }
                GigShow.mapCss(gd, gg.element, css);
                gg.addTilt(gd.tilt);
            }));
            if (this.editor != null) {
                awx.addDx(ss.Delegate.create(this, function() {
                    this.editor.makeDraggable(gg);
                }));
            }
            awx.commit(awp);
        }
        else {
            throw new Error(Exceptions.format(Exceptions.missingDomElement, Exceptions.fn(arguments)));
        }
        return gg;
    },
    
    loadActionAw: function GigShow$loadActionAw(awp) {
        /// <param name="awp" type="Await">
        /// </param>
        new Await().addDl(ss.Delegate.create(this, function(aw) {
            ThemeYoshi.currentLoadCss = this.get_currentSlide().loadCss;
            StaticBuild.LoadCssAw(aw, this.get_currentSlide().loadCss);
        })).addDl(ss.Delegate.create(this, function(aw) {
            ThemeYoshi.currentLoadLibs = this.get_currentSlide().load;
            StaticBuild.LoadLibsAw(aw, this.get_currentSlide().load);
        })).commit(awp);
    },
    
    buildAction: function GigShow$buildAction() {
        var sd = this.get_currentSlide();
        ThemeYoshi.currentBuildAction = sd.build;
        window.setTimeout(function() {
            if (sd.curate != null && !ThemeBase.publishing) {
                var actions = sd.curate.split(',');
                var $enum1 = ss.IEnumerator.getEnumerator(actions);
                while ($enum1.moveNext()) {
                    var act = $enum1.current;
                    try {
                        eval(act.trim() + '()');
                    }
                    catch (ex) {
                        Inform.error('Slide curate error: {0}: {1}', act, ex);
                    }
                }
            }
            if (sd.build != null && !ThemeBase.publishing && ThemeBase.activePage) {
                var actions = sd.build.split(',');
                var $enum2 = ss.IEnumerator.getEnumerator(actions);
                while ($enum2.moveNext()) {
                    var act = $enum2.current;
                    try {
                        eval(act.trim() + '()');
                    }
                    catch (ex) {
                        Inform.error('Slide build error: {0}: {1}', act, ex);
                    }
                }
            }
            var pgAction = Nsb.Storage.getSession(ThemeBase.pageActionKey);
            if (!String.isNullOrEmpty(pgAction)) {
                Nsb.Storage.removeSession(ThemeBase.pageActionKey);
                window.setTimeout(function() {
                    eval(pgAction);
                }, 13);
            }
        }, 1);
    },
    
    changeSlideEv: function GigShow$changeSlideEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.restoreSlideAw(Await.get_asyncAw(), parseInt($(e.target).val()));
        this.stopSlidesEv(e);
    },
    
    nextSlide: function GigShow$nextSlide() {
        GigShow.pageSelectToEl.children().fadeOut(200);
        new Await().sleep(200).addDx(ss.Delegate.create(this, function() {
            this.restoreSlideAw(Await.get_asyncAw(), (this.slide + 1 >= this.slides.length) ? 0 : this.slide + 1);
            $('select', this.slideControls).val(this.slide.toString());
        })).commit();
    },
    
    nextSlideEv: function GigShow$nextSlideEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.restoreSlideAw(Await.get_asyncAw(), (this.slide + 1 >= this.slides.length) ? 0 : this.slide + 1);
        $('select', this.slideControls).val(this.slide.toString());
        this.stopSlidesEv(e);
        DomElement.cancelEvent(e);
    },
    
    prevSlideEv: function GigShow$prevSlideEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.restoreSlideAw(Await.get_asyncAw(), (this.slide - 1 < 0) ? this.slides.length - 1 : this.slide - 1);
        $('select', this.slideControls).val(this.slide.toString());
        this.stopSlidesEv(e);
        DomElement.cancelEvent(e);
    },
    
    addSlideEv: function GigShow$addSlideEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.stopSlidesEv(e);
        new Await().addDx(ss.Delegate.create(this, function() {
            var slide = new WhirliGig.Classes.SlideData();
            slide.slide = this.slide = this.slides.length;
            slide.gigs = {};
            this.slides.add(slide);
            new Await().addAw(ss.Delegate.create(this, this.restoreSlideAw), this.slide).addDl(ss.Delegate.create(this, function(aw) {
                this.redrawPageGear();
                var ths = this;
                ths.saveAllAw(aw);
            })).commit();
        })).commit();
    },
    
    remSlideEv: function GigShow$remSlideEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        this.stopSlidesEv(e);
        new Await().addAw(ss.Delegate.create(new Ask(), new Ask().okCancelAw), 'Delete this slide for sure?').addAw(DomElement.requireResultAw, true).addDx(ss.Delegate.create(this, function() {
            this.slides.removeAt(this.slide);
            if (!this.slides.length) {
                this.slides.add(GigShow.blankSlide());
            }
            var cnt = 0;
            var $enum1 = ss.IEnumerator.getEnumerator(this.slides);
            while ($enum1.moveNext()) {
                var sd = $enum1.current;
                sd.slide = cnt++;
            }
            new Await().addAw(ss.Delegate.create(this, this.restoreSlideAw), Math.max(this.slide - 1, 0)).addDl(ss.Delegate.create(this, function(aw) {
                this.redrawPageGear();
                var ths = this;
                ths.saveAllAw(aw);
            })).commit();
        })).commit();
    },
    
    playSlidesEv: function GigShow$playSlidesEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        window.clearInterval(this._playTmr);
        this._playTmr = window.setInterval(ss.Delegate.create(this, this.nextSlide), this.get_currentSlide().interval);
        this.restoreSlideAw(Await.get_asyncAw(), this.slide);
        this.redrawPageGear();
    },
    
    stopSlidesEv: function GigShow$stopSlidesEv(e) {
        /// <param name="e" type="jQueryEvent">
        /// </param>
        if (this._playTmr > 0) {
            window.clearInterval(this._playTmr);
            this._playTmr = 0;
            this.restoreSlideAw(Await.get_asyncAw(), this.slide);
        }
        this.redrawPageGear();
    },
    
    normalize: function GigShow$normalize(sd) {
        /// <param name="sd" type="WhirliGig.Classes.SlideData">
        /// </param>
        sd.css = $.extend({}, ThemeYoshi.defaultPageCss, sd.css);
        var $dict1 = sd.gigs;
        for (var $key2 in $dict1) {
            var p = { key: $key2, value: $dict1[$key2] };
            if (p.value.type === 'TextItem') {
                p.value.html = p.value.html.replaceAll('<p>', "<div class='GigC'>").replaceAll('</p>', '</div>');
            }
        }
    },
    
    setMinPageHeight: function GigShow$setMinPageHeight() {
        var pageEnd = 0;
        var $enum1 = ss.IEnumerator.getEnumerator(this.slides);
        while ($enum1.moveNext()) {
            var sd = $enum1.current;
            if (sd.gigs != null && Object.getKeyCount(sd.gigs) > 0) {
                var $dict2 = sd.gigs;
                for (var $key3 in $dict2) {
                    var p = { key: $key3, value: $dict2[$key3] };
                    if (!p.value.floated) {
                        pageEnd = Math.max(p.value.off.top + p.value.dim.height, pageEnd);
                    }
                }
            }
        }
        var el = GigShow.pageSelectToEl;
        var mh = pageEnd - el.offset().top - 10;
        if (mh < 0) {
            mh = 0;
        }
        el.height(mh);
    },
    
    curatingOff: function GigShow$curatingOff() {
        Nsb.Storage.setLocal(ThemeYoshi.get_curatingKey(), false);
        ThemeYoshi.reloadPage();
    }
}


ThemeWhirliGig.registerClass('ThemeWhirliGig', ThemeBase);
Gig.registerClass('Gig', Actor);
WhirliGig.Classes.SlideData.registerClass('WhirliGig.Classes.SlideData');
WhirliGig.Classes.GigData.registerClass('WhirliGig.Classes.GigData');
WhirliGig.Classes.Pos.registerClass('WhirliGig.Classes.Pos');
WhirliGig.Classes.Dimension.registerClass('WhirliGig.Classes.Dimension');
WhirliGig.Classes.GigShowConfig.registerClass('WhirliGig.Classes.GigShowConfig');
GigShow.registerClass('GigShow', PkgBase);
ThemeWhirliGig.addSlideTitle = 'Add a slide';
ThemeWhirliGig.nextSlideTitle = 'Next slide';
ThemeWhirliGig.prevSlideTitle = 'Previous slide';
ThemeWhirliGig.remSlideTitle = 'Remove this slide';
ThemeWhirliGig.deleteMsg = 'Delete this slide for sure?';
ThemeWhirliGig.pageAddBtnTitle = 'add new page';
ThemeWhirliGig.pageCancelBtnTitle = 'cancel page changes';
ThemeWhirliGig.pageAddDoneTitle = 'apply changes';
ThemeWhirliGig._initialized$1 = Helpers.staticInheritClass((ThemeWhirliGig).get_name(), (ThemeBase).get_name());
Gig.deefCss = { 'padding-top': 8, 'padding-left': 16 };
Gig._extractGigClassRx$3 = new RegExp('<gigclass:\\s*(.*)\\s*/>', 'g');
GigShow.pageSelectTo = null;
GigShow.pageSelectToEl = null;
GigShow.instance = null;
GigShow.cssMap = { Button: { inner: 'button', rounding: false, css: true, doubleclick: true }, TextBox: { inner: 'input[type=text]', rounding: true, css: true, doubleclick: true }, TextArea: { inner: 'textarea', rounding: true, css: true, doubleclick: true }, TextItem: { inner: '.GigC', rounding: true, css: false, doubleclick: true }, DropImage: { inner: 'img', rounding: true, css: false, doubleclick: false } };
})();

//! This script was generated using Script# v0.7.4.0
